package com.hyc.controller;

import com.carrotsearch.sizeof.RamUsageEstimator;
import com.hyc.entity.Person;
import org.openjdk.jol.info.ClassLayout;
import org.openjdk.jol.info.GraphLayout;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MainController {
    public String simple() {
        Person person = new Person();
        System.out.println(RamUsageEstimator.sizeOf(person));
        System.out.println(ClassLayout.parseInstance(person).toPrintable());
        return "success";
    }

    public static void main(String[] args) {
        char a = 'a';
        System.out.println(RamUsageEstimator.sizeOf(a));

        System.out.println("================================================================================================");
        //打印实例的内存布局
        System.out.println(ClassLayout.parseInstance(a).toPrintable());
        System.out.println("=================================================");
        //打印对象的所有相关内存占用
        System.out.println(GraphLayout.parseInstance(a).toPrintable());
        System.out.println("=================================================");
        //打印对象的所有内存结果并统计
        System.out.println(GraphLayout.parseInstance(a).toFootprint());
    }
}
